'Zaklada uzytkownika w ipj.gov.pl
'Obecna skladnia wejscia:
'Imie;Nazwisko;ID;Dzial (pelna nazwa);Departament (skrocona nazwa dzialu);Pokoj;Telefon;Instytucja (IPJ);Komorka Organizacyjna (miejsce w AD - puste);Mail(dla kontaktu);P@ssw0rd
'np.:
'Adam;Testowy;11111;Dzial Marketingu;DM;pok 103;22 718 3456;IPJ;NST;;;
'wszystkie linie WScript.StdOut.Write("tekst") zostana zamieszczone w wynikowym mailu
'na razie jest to w kilku miejscach zaproponowanych przeze mnie, ale mozna dac tego wiecej/mniej

Option Explicit

Dim oRootDSE
Dim sDomain
Dim oContainer
Dim oUser

Dim sFirstName
Dim sLastName
Dim sUserName
Dim sFullName
Dim sEmployeeID
Dim sOfficeLocations
Dim sTelephoneNumber
Dim sDescription
Dim sDepartment
Dim sCompany
Dim sDivision
Dim sLoginScript
Dim sMail

Dim sOneLine
Dim saUserData

Dim sCommandLineArgs

Set sCommandLineArgs = wscript.Arguments

Set oRootDSE = GetObject("LDAP://rootDSE")
sDomain = oRootDSE.Get("defaultNamingContext")
Set oContainer = GetObject("LDAP://ou=CISExchangeDaemon,ou=Instytut," & sDomain)


sLoginScript = "login.bat"


WScript.StdOut.Write("Wczytywanie danych wejsciowych")
WScript.StdOut.WriteBlankLines(1)

sOneLine = sCommandLineArgs(0)
saUserData = Split(sOneLine, ";", -1, 1)

sFirstName       = saUserData(0) '"Jan"
sLastName        = saUserData(1) '"Abacki"
sUserName        = saUserData(1) & left(sFirstName, 1) '"AbackiJ"
sEmployeeID      = saUserData(2) '"102"
sFullName        = sLastName & " " & sFirstName
sDivision        = saUserData(3) '"Dzial Ekonomiczno-Handlowy"
sDepartment	 = saUserData(4) '"DEH"
sOfficeLocations = saUserData(5) '"bud.7, pok.21"
sTelephoneNumber = saUserData(6) '"718 05 35"
sDescription     = sLastName & " " & sFirstName & ", " & sDivision & ", " & sOfficeLocations
sCompany	 = saUserData(7) '"IPJ"
sMail		 = left(sFirstName, 1) & "." & sLastName & "@ipj.gov.pl"


WScript.StdOut.Write("Poprawnie wczytano dane wejsciowe")
WScript.StdOut.WriteBlankLines(1)

WScript.StdOut.Write("Tworzenie usera w AD")
WScript.StdOut.WriteBlankLines(1)

Set oUser = oContainer.Create("User", "cn=" & sFullName)
oUser.Put "sAMAccountName", sUserName
oUser.SetInfo

oUser.GetInfo
oUser.AccountDisabled = FALSE
oUser.SetInfo

oUser.GetInfo
oUser.Put "givenName", sFirstName
oUser.Put "sn", sLastName
oUser.Put "displayName", sFullName
oUser.Put "userPrincipalName", sUserName & "@ipj.gov.pl"
oUser.Put "description", sDescription
oUser.Put "employeeID", sEmployeeID
oUser.Put "physicalDeliveryOfficeName", sOfficeLocations
oUser.Put "telephoneNumber", sTelephoneNumber
oUser.Put "department", sDepartment
oUser.Put "division", sDivision
oUser.Put "scriptPath", sLoginScript
oUser.Put "mailNickname", left(sFirstName, 1) & "." & sLastName
oUser.Put "company", sCompany
oUser.Put "mail", sMail
oUser.SetInfo

oUser.GetInfo
oUser.Put "pwdLastSet", -1
oUser.SetInfo


WScript.StdOut.Write("Poprawnie wpisano do AD")
WScript.StdOut.WriteBlankLines(1)

WScript.StdOut.Write("Tworzenie skrzynki Exchange")
WScript.StdOut.WriteBlankLines(1)

oUser.CreateMailbox "LDAP://CN=Mailbox Store (HERMES),CN=First Storage Group,CN=InformationStore,CN=HERMES,CN=Servers,CN=SWIERK,CN=Administrative Groups,CN=IPJ,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=ipj,DC=gov,DC=pl"

oUser.SetInfo

WScript.StdOut.Write("Poprawnie stworzono skrzynke pocztowa")
WScript.StdOut.WriteBlankLines(1)
